package com.redis.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/8/2 17:35
 */
@Configuration
public class JedisConfig {
    // 日志
    private static final Logger LOGGER= LoggerFactory.getLogger(JedisConfig.class);
    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.jedis.pool.max-active}")
    private int max_active;
    @Value("${spring.redis.jedis.pool.max-idle}")
    private int max_idle;
    @Value("${spring.redis.jedis.pool.min-idle}")
    private int min_idle;
    @Value("${spring.redis.timeout}")
    private int timeout;
    @Bean
    public JedisPool jedisPool(){
        // 创建配置对象
        JedisPoolConfig jedisPoolConfig=new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(max_idle);
        jedisPoolConfig.setMinIdle(min_idle);
        jedisPoolConfig.setMaxTotal(max_active);
        LOGGER.info("连接redis成功");
        JedisPool jedisPool=new JedisPool(jedisPoolConfig,host,port,timeout);
        return jedisPool;
    }

}
